import { propertyTypeMap, judgeTypeMap } from '@/config/dict'
import { CustomStatus } from '@/components'

export const tableColumn = (handleEdit, handleDelete) => {
  return [
    {
      key: 'propertyName',
      label: '属性名称',
      minWidth: 120
    },
    {
      key: 'propertyType',
      label: '属性类型',
      minWidth: 120
    },
    {
      key: 'promptText',
      label: '文本提示',
      minWidth: 120
    },
    {
      key: 'sortNumber',
      label: '排序号',
      minWidth: 120
    },
    {
      key: 'required',
      label: '是否必填',
      minWidth: 120,
      render: (h, scope) => <CustomStatus list={judgeTypeMap} value={scope.row.required} />
    },
    {
      type: 'button',
      label: '操作',
      list: [
        {
          name: '修改',
          click: handleEdit
        },
        {
          name: '删除',
          confirm: '确认删除吗?',
          click: handleDelete
        }
      ]

    }
  ]
}

export const renderFormItem = (handlePropertyTypeChange, isHide) => [
  {
    type: 'input',
    key: 'propertyName',
    label: '属性名称',
    required: true,
    col: 12
  },
  {
    type: 'select',
    key: 'propertyType',
    label: '属性类型',
    slotAttrs: {
      options: propertyTypeMap
    },
    slotListeners: {
      change: handlePropertyTypeChange
    },
    required: true,
    col: 12
  },
  {
    type: 'input',
    key: 'promptText',
    label: '文本提示',
    col: 12
  },
  {
    type: 'input',
    key: 'sortNumber',
    label: '排序号',
    slotAttrs: {
      type: 'number',
      placeholder: '越小越在前'
    },
    col: 12
  },
  {
    type: 'radio',
    key: 'required',
    label: '是否必填',
    slotAttrs: {
      options: judgeTypeMap
    },
    required: true,
    col: 24
  },
  {
    type: 'input',
    key: 'options',
    label: '选择项',
    isHide,
    slotAttrs: {
      placeholder: "以'|'隔开",
      style: { width: '94%' }
    },
    col: 24
  }
]

// form 按钮
export const formButtons = (onSubmit, onReset) => {
  return {
    isDialog: true,
    submitName: '提交',
    resetName: '取消',
    submitCallback: values => onSubmit(values),
    resetCallback: () => onReset()
  }
}

// rules 规则
// export const formRules = {
//   propertyName: [
//     { required: true, message: '请输入属性名称!', trigger: 'blur' }
//   ],
//   propertyType: [
//     { required: true, message: '请选择属性类型!', trigger: 'change' }
//   ],
//   required: [
//     { required: true, message: '请选择是否必填!', trigger: 'change' }
//   ]
// }

